package com.baike.controller;

import com.baike.data.Result;
import com.baike.domain.VideoLearnedStatusDTO;
import com.baike.em.ConstantEnum;
import com.baike.domain.ProgressRequestDTO;
import com.baike.service.WatchHistoryService;
import com.baike.util.IdWorker;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author:pjm
 */
@RestController
@RequestMapping("historyController")
@Api(value = "学生学习记录服务管理")
@RefreshScope //开启自动刷新配置
public class WatchHistoryController {

    @Autowired
    private WatchHistoryService watchHistoryService;
    @Autowired
    private MongoTemplate mongoTemplate;

    //学习时长表增加记学习记录
    @ApiOperation(value = "学生学习记录增加接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name="lessonId",value = "课程id",required = false,paramType = "query"),
            @ApiImplicitParam(name="studentId",value = "(学生)id",required = true,paramType = "query"),
            @ApiImplicitParam(name="incrementTime",value = "增量时间",required = true,paramType = "query"),
            @ApiImplicitParam(name="videoDuration",value = "视频总时长",required = true,paramType = "query"),
            @ApiImplicitParam(name="videoProgress",value = "视频播放位置",required = true,paramType = "query"),
    })
    @PostMapping
    public Result addWatch(ProgressRequestDTO progressRequest){
        IdWorker idWorker = new IdWorker();
        progressRequest.setVideoId(idWorker.nextId());
        ProgressRequestDTO studentWatch = mongoTemplate.save(progressRequest);
        return Result.build(ConstantEnum.INSERT_SUCCESS).setResult(studentWatch);
    }





}
